package cn.go.bus;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import cn.go.buster.ThreadMode;
import cn.go.buster.annotation.GoBus;
import cn.go.buster.launcher.api.GoBuster;

/**
 * @author logcat
 */
public class TestFragment extends Fragment {

    private String TAG = this.getClass().getSimpleName();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_test , container , false);
        GoBuster.getInstance().register(this);
        Button btnFragmentToActivity = rootView.findViewById(R.id.btnFragmentToActivity);
        btnFragmentToActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GoBuster.getInstance().post("tag1" , "value2");
            }
        });
        return rootView;
    }



    @GoBus(tag = "tag4" , threadMode = ThreadMode.MAIN)
    public void testMethod4(){
        Log.d(TAG, "testMethod4: ");
        Toast.makeText(getActivity(), "testMethod4", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        GoBuster.getInstance().unRegister(this);
    }
}
